
from google.appengine.ext import db


class Author(db.Model):
  nickname = db.StringProperty()
  user = db.UserProperty()

class Resource(db.Model):
  ''' Images and other files as well as cached pages '''
  domain = db.StringProperty()
  path = db.StringProperty()
  mime = db.StringProperty(default=u'text/html; charset=UTF-8'.encode('utf-8'))
  content = db.BlobProperty()
  author = db.UserProperty()
  publish = db.DateTimeProperty(auto_now_add=True)
  modified = db.DateTimeProperty(auto_now=True)
  created = db.DateTimeProperty(auto_now_add=True)


class Template(db.Model):
  name = db.StringProperty()
  author = db.StringProperty()
  theme = db.StringProperty()
  html = db.TextProperty()
  xml = db.TextProperty()
  compiled = db.TextProperty()
  modified = db.DateTimeProperty(auto_now=True)
  created = db.DateTimeProperty(auto_now_add=True)


class Page(db.Model):
  # these properties are cached here, but will update with the latest revision
  domain = db.StringProperty()
  path = db.StringProperty()
  template = db.ReferenceProperty(Template)
  author = db.UserProperty()
  publish = db.DateTimeProperty(auto_now_add=True)
  created = db.DateTimeProperty(auto_now_add=True)


class Content(db.Model):
  page = db.ReferenceProperty(Page)
  field = db.StringProperty()
  value = db.TextProperty()
  shareable = db.BooleanProperty()
  created = db.DateTimeProperty(auto_now_add=True)
  
